package com.xuzz.study.spring.bean.lifecyle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

public class ExampleBean implements BeanNameAware, InitializingBean, BeanFactoryAware, DisposableBean, EnvironmentAware {

    private Long customerId;
    private String customerName;
    private String desc;
    private BeanFactory beanFactory;
    private String beanName;


    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
        System.out.println("【BeanFactoryAware】的setBeanFactory方法执行");
    }

    @Override
    public void setBeanName(String s) {
        this.beanName =s;
        System.out.println("【BeanNameAware】的setBeanName方法执行");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("【InitializingBean】的afterPropertiesSet方法执行");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("【DisposableBean】的destroy方法执行");
    }


    public void initCustomer() throws Exception {
        System.out.println("【Init-method】的initCustomer方法执行");
    }


    public void destroyCustomer() throws Exception {
        System.out.println("【destroy-method】的destroyCustomer方法执行");
    }

    public Long getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String info(){
        return this.getCustomerId()+"/"
                +this.getCustomerName()+"/"+this.getDesc();
    }

    @Override
    public void setEnvironment(Environment environment) {
        System.out.println("EnviromentAware 的setEnvironment方法");
    }
}
